package com.jin290.mqlibrary;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.RelativeLayout;
import android.widget.TextView;

import java.util.List;

/**
 * Created by MQ on 2016/9/18.
 */
public class CourseAdapter extends BaseAdapter {
    private Context mContext;
    private List<CourseBean> mCourseBeanList;


    public CourseAdapter(Context context) {
        mContext = context;
    }

    public void getdata(List<CourseBean> CourseBeanList) {
        mCourseBeanList = CourseBeanList;
    }

    @Override
    public int getCount() {
        return mCourseBeanList.size();
    }

    @Override
    public Object getItem(int position) {
        return mCourseBeanList.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View view, ViewGroup parent) {
        Viewh viewh;
        if (view == null) {
            view = LayoutInflater.from(mContext).inflate(R.layout.item_course, null);
            viewh = new Viewh();

            viewh.rel_course_line = (RelativeLayout) view.findViewById(R.id.rel_course_line);
            viewh.tv_course = (TextView) view.findViewById(R.id.tv_course);
            viewh.rel_course = (RelativeLayout) view.findViewById(R.id.rel_course);

            view.setTag(viewh);
        } else {
            viewh = (Viewh) view.getTag();//取出ViewHolder对象
        }


        if (!mCourseBeanList.get(position).getCourse().equals("-")) {
            viewh.tv_course.setText(mCourseBeanList.get(position).getCourse());
        } else {
            viewh.tv_course.setText("");
        }


        if (mCourseBeanList.get(position).isB() == true) {
            viewh.rel_course.setBackgroundResource(R.color.register_line);
        } else {
            viewh.rel_course.setBackgroundResource(R.drawable.course);
        }


        if (position == 15) {
            viewh.rel_course_line.setVisibility(View.VISIBLE);
        }
        if (position == 16) {
            viewh.rel_course_line.setVisibility(View.VISIBLE);
        }

        if (position == 17) {
            viewh.rel_course_line.setVisibility(View.VISIBLE);
        }
        if (position == 18) {
            viewh.rel_course_line.setVisibility(View.VISIBLE);
        }
        if (position == 19) {
            viewh.rel_course_line.setVisibility(View.VISIBLE);
        }


        return view;
    }


    public class Viewh {

        RelativeLayout rel_course_line;
        RelativeLayout rel_course;
        TextView tv_course;
    }

}
